﻿//-----------------------------------------------------------------------------------------------------------
// WBFSSync Project by Omega Frost 
// http://wbfssync.codeplex.com/
//
// WBFSSync is Licensed under the terms of the 
// Microsoft Reciprocal License (Ms-RL)
//-----------------------------------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using WbfsSync.Core;

namespace WbfsSync.Controls
{
    //-------------------------------------------------------------------------------------------------------
    // Interaction logic for ViewSelector.xaml
    //-------------------------------------------------------------------------------------------------------
    public partial class ViewSelector : Window
    {
        //---------------------------------------------------------------------------------------------------
        //
        //---------------------------------------------------------------------------------------------------
        public BrowserMode SelectedMode = BrowserMode.Tile;
        protected bool isClosing = false;


        //---------------------------------------------------------------------------------------------------
        //
        //---------------------------------------------------------------------------------------------------
        public event EventHandler SelectedModeChanged;


        //---------------------------------------------------------------------------------------------------
        //
        //---------------------------------------------------------------------------------------------------
        public ViewSelector()
        {
            InitializeComponent();
            this.SelectedMode = Config.BrowserMode;
            this.mainSlider.Value = this.mainSlider.Ticks[(int)this.SelectedMode];
        }


        //---------------------------------------------------------------------------------------------------
        //
        //---------------------------------------------------------------------------------------------------
        protected override void OnDeactivated(EventArgs e)
        {
            base.OnDeactivated(e);
            if (!isClosing) Close();
        }


        //---------------------------------------------------------------------------------------------------
        //
        //---------------------------------------------------------------------------------------------------
        void SetExtraLargeIcons(object sender, RoutedEventArgs e)
        {
            SelectedMode = BrowserMode.Extra;
            
            if (this.SelectedModeChanged != null)
                this.SelectedModeChanged(this, EventArgs.Empty);

            isClosing = true;
            Close();
        }


        //---------------------------------------------------------------------------------------------------
        //
        //---------------------------------------------------------------------------------------------------
        void SetLargeIcons(object sender, RoutedEventArgs e)
        {
            SelectedMode = BrowserMode.Large;

            if (this.SelectedModeChanged != null)
                this.SelectedModeChanged(this, EventArgs.Empty);

            isClosing = true;
            Close();
        }


        //---------------------------------------------------------------------------------------------------
        //
        //---------------------------------------------------------------------------------------------------
        void SetMediumIcons(object sender, RoutedEventArgs e)
        {
            SelectedMode = BrowserMode.Medium;

            if (this.SelectedModeChanged != null)
                this.SelectedModeChanged(this, EventArgs.Empty);

            isClosing = true;
            Close();
        }


        //---------------------------------------------------------------------------------------------------
        //
        //---------------------------------------------------------------------------------------------------
        void SetSmallIcons(object sender, RoutedEventArgs e)
        {
            SelectedMode = BrowserMode.Small;

            if (this.SelectedModeChanged != null)
                this.SelectedModeChanged(this, EventArgs.Empty);

            isClosing = true;
            Close();
        }


        //---------------------------------------------------------------------------------------------------
        //
        //---------------------------------------------------------------------------------------------------
        void SetDetailIcons(object sender, RoutedEventArgs e)
        {
            SelectedMode = BrowserMode.Detail;

            if (this.SelectedModeChanged != null)
                this.SelectedModeChanged(this, EventArgs.Empty);

            isClosing = true;
            Close();
        }


        //---------------------------------------------------------------------------------------------------
        //
        //---------------------------------------------------------------------------------------------------
        void SetTileIcons(object sender, RoutedEventArgs e)
        {
            SelectedMode = BrowserMode.Tile;

            if (this.SelectedModeChanged != null)
                this.SelectedModeChanged(this, EventArgs.Empty);

            isClosing = true;
            Close();
        }


        //---------------------------------------------------------------------------------------------------
        //
        //---------------------------------------------------------------------------------------------------
        private void SliderValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            SelectedMode = (BrowserMode)(sender as Slider).Ticks.IndexOf(e.NewValue);

            if (this.SelectedModeChanged != null)
                this.SelectedModeChanged(this, EventArgs.Empty);
        }
    }
}
